<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../react18/react.development.js"></script>
    <script src="../react18/react-dom.development.js"></script>
    <script src="../react18/babel.min.js"></script>
  </head>
  <body>
    <div id="app"></div>
    <script type="text/babel">
      class Child extends React.Component {
        state = {
          b: 2,
        };
        static getDerivedStateFromProps(props, state) {
          const { a } = props;
          return { myA: a };
        }
        shouldComponentUpdate() {
          console.log("shouldComponentUpdate");
          return false;
        }
        render() {
          return (
            <div>
              <h2>Child组件</h2>
            </div>
          );
        }
        componentDidUpdate() {
          console.log("子组件componentDidUpdate");
        }
        componentDidMount() {
          console.log("子组件渲染完成");
        }
      }
      class App extends React.Component {
        state = {
          count: 0,
        };
        static getDerivedStateFromProps(props, state) {
          console.log(a, state, "getDerivedStateFromProps,父组件");
          const { a } = props;
          return { myA: a };
        }
        render() {
          console.log("-----render-----");
          const { count } = this.state;
          return (
            <div>
              <Child a="1" />
              <h2>App组件:{count}</h2>
              <button
                onClick={() => {
                  this.setState({ count: count + 1 });
                }}
              >
                count累加
              </button>
            </div>
          );
        }
        getSnapshotBeforeUpdate(){
            console.log("getSnapshotBeforeUpdate");
            return null;
        }
        componentDidupdate(){
            console.log("父组件componentDidUpdate");
        }
        componentDidMount(){
            console.log("父组件渲染完成")
        }
        
      }
      ReactDOM.createRoot(document.getElementById("app")).render(<App />);
    </script>
  </body>
</html>
